﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;

using System.Runtime.InteropServices;
struct PixHelper
{
    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("d3d9.dll",
        EntryPoint = "D3DPERF_BeginEvent",
        CharSet = CharSet.Auto,
        CallingConvention = CallingConvention.Winapi)]
    public static extern int BeginEvent(uint col, string wszName);

    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("d3d9.dll",
        EntryPoint = "D3DPERF_EndEvent",
        CallingConvention = CallingConvention.Winapi)]
    public static extern int EndEvent();

    [System.Security.SuppressUnmanagedCodeSecurity]
    [DllImport("d3d9.dll",
        EntryPoint = "D3DPERF_SetMarker",
        CharSet = CharSet.Auto,
        CallingConvention = CallingConvention.Winapi)]
    public static extern void SetMarker(uint col, string wszName);
};

namespace mirror
{
    class cVFXManager : Singleton<cVFXManager>
    {
        List<cVFXBase> mEffects;

        public cVFXManager()
        {
            mEffects = new List<cVFXBase>(32);
        }

        public void Update(GameTime zGameTime)
        {
            for (int nEffect = 0; nEffect < mEffects.Count; nEffect++)
            {
                bool isStillActive = mEffects[nEffect].Update(zGameTime);

                //  Does effect need to be removed?
                if (!isStillActive)
                {
                    mEffects.RemoveAt(nEffect);
                    nEffect--;
                    continue;
                }
            }
            // Update particle systems
            // foreach (KeyValuePair<String, PSGPU.ParticleSystem> ps in clusterPS)
            //    ps.Value.Update(zGameTime);

            
        }

        public void Reset()
        {
            mEffects.Clear();
        }

        public void Draw()
        {
            foreach (cVFXBase myVFX in mEffects)
            {
                myVFX.Draw();
            }
        }

        public void AddEffect(cVFXBase zVFX)
        {
            mEffects.Add(zVFX);
        }
    }


}
